<template>
	<view class="page-center">
		<!-- <nav-bar title="报价" :showLeftIcon="true" :leftSlot="false"></nav-bar> -->

		<view class="quotatin" :style="{'height': scrollHeight}">
			<view class="quotatin-item">
				<view class="base-info">
					<view class="base-info-left row-column-center">
						<!-- 头像缺 -->
						<image class="header-img" src="@/static/images/headerDefault.png" mode="widthFix"></image>
						<text>{{item.nickName || 'XX用户'}}</text>
					</view>
					<view class="release-item">
						{{detail.createTime}}发布
					</view>
				</view>
				<view class="to-place">
					<text>{{fomatterAdressName(detail.startProvince)}} {{fomatterAdressName(detail.startCity)}}</text>
					<image src="@/static/images/public/to-hear.png" mode=""></image>
					<text>{{fomatterAdressName(detail.endProvince)}} {{fomatterAdressName(detail.endCity)}}</text>
				</view>
				<view class="car-info">
					<text>{{forrmatterEnmu(Enmu.vehicleType, detail.vehicleType)}}</text>
					<text style="margin: 0 10rpx;">/</text>
					<text>{{detail.quantity}}台</text>
					<text style="margin: 0 10rpx;">/</text>
					<text>{{forrmatterEnmu(Enmu.carStatusList, detail.vehicleStatus)}}</text>
				</view>
				<view class="check-time">
					<text>托运日期：{{detail.shippingDate}}</text>
					<text class="dimension" v-if="detail.shippingDate && isTomorrow(detail.shippingDate)">(明天)</text>
				</view>
			</view>
			
			<view class="info-fillin">
				<view class="fillin-item">
					<view class="fillin-item-title">预计到达时间</view>
					<view class="fillin-item-content" @click="selectTime">
						<view class="selct-placeholder" v-if="formData.estimatedArrivalTime == ''">请选择</view>
						<view v-else>
							{{formData.estimatedArrivalTime}}
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
				<view class="fillin-item">
					<view class="fillin-item-title">预计总价（元）</view>
					<view class="fillin-item-content">
						<u-input
							border="false"
							v-model="formData.price"
							type="number"
							input-align="right"
							placeholder="请填写"
							placeholder-style="color: #999;font-size: 28rpx"/>
					</view>
				</view>
			</view>
		</view>



		<!-- 电话联系  报价 -->
		<view class="opeart">
			<view class="opeart-btn opeart-quotation" @click="submit">
				<text>提交报价</text>
			</view>
		</view>


		<u-datetime-picker
			:show="isShowTime"
			v-model="timeValue"
			ref="datetimePicker"
			mode="date"
			:minDate="Number(new Date())"
			@cancel="isShowTime = false"
			@confirm="selectTimeConfirm"
		></u-datetime-picker>
	</view>
</template>

<script>
	import Transport from '@/api/transport.js'
	import {forrmatterEnmu, isTomorrow, timestampToDate} from '@/utils/index.js'
	import Enmu from '@/utils/enmu.js'
	import userCenter from '@/api/userCenter.js'
	import {fomatterAdressName, showConfirm} from '@/utils/common.js'
	export default {
		data() {
			return {
				Enmu,
				scrollHeight: '',
				isShowTime: false,
				timeValue: Number(new Date()),
				detail: {},
				formData: {
					estimatedArrivalTime: '',
					price: ''
				},
				userName: ""
			}
		},
		async onLoad(e) {
			this.scrollHeight = this.$store.getters.heightData.noTabMainHeight;
			if(e.id) {
				this.itemId = e.id;
				this.getDetail();
			}
			this.userName = uni.getStorageSync('userName');
			console.log(this.$store.getters.heightData);
			
		},
		methods: {
			forrmatterEnmu,
			isTomorrow,
			fomatterAdressName,
			navigator(url) {
				uni.navigateTo({
					url
				})
			},
			selectTime() {
				this.isShowTime = true;
			},
			async getDetail() {
				let res = await Transport.getDemandDetail(this.itemId);
				this.detail = res.data;
			},
			selectTimeConfirm(e) {
				let time = timestampToDate(e.value, 'ymd');
				this.formData.estimatedArrivalTime = time;
				this.isShowTime = false;
			},
			// 提交规则校验
			verifyRule() {
				if(this.formData.estimatedArrivalTime == '') {
					uni.showToast({
						title: "请选择预计到达时间",
						icon: "none"
					})
					return false;
				}
				if(this.formData.price == '') {
					uni.showToast({
						title: "请选择预计总价",
						icon: "none"
					})
					return false;
				}
				return true;
			},
			// 提交报价
			async submit() {
				if(!this.verifyRule()) return;
				let res = await Transport.addQuote({
					...this.formData,
					demandId: this.detail.id
				})
				if(res.code == 200) {
					userCenter.setLogCount({
						callType: 3,
						demandId: this.detail.id,
						phoneNumber: this.userName,
					}).then(res => {
						uni.showToast({
							title: "报价成功",
							icon: 'none'
						});
						setTimeout(() => {
							uni.switchTab({
								url: '/pages/transport'
							})
						},1000)
					})
					
					
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page-center {
		font-family: "PingFang SC";
		font-size: 26rpx;
		position: relative;
		background: #f6f6f6;
		width: 100%;
		height: 100vh;
		position: relative;
	}

	.flex-sp {
		display: flex;
		justify-content: space-between;
	}

	.quotatin {
		overflow-y: auto;
		.quotatin-item {
			background-color: #fff;
			padding: 40rpx 28rpx;
		}
		.base-info {
			display: flex;
			font-size: 24rpx;
			color: #333;
			justify-content: space-between;
			align-items: center;
			line-height: 1;

			.base-info-left {
				display: flex;
				line-height: 1;
			}

			.header-img {
				width: 36rpx;
				height: 36rpx;
				margin-right: 12rpx;
			}

			.release-item {
				color: #999;
			}
		}

		.to-place {
			font-size: 30rpx;
			color: #1A1A1A;
			margin-top: 10rpx;

			image {
				width: 35rpx;
				height: 8rpx;
				margin: 0 12rpx;
				vertical-align: middle;
			}

			.place-number {
				font-size: 44rpx;
				color: #1777FF;
			}
		}

		.car-info {
			color: #ff7512;
			font-size: 26rpx;
			margin-top: 20rpx;
			line-height: 1;
		}

		.check-time {
			color: #9F9F9F;
			font-size: 24rpx;
			margin-top: 18rpx;
			line-height: 1;

			.dimension {
				color: #1777ff;
				margin: 20rpx;
			}

			.dimension-fill {
				color: #1C1C1C;
				font-size: 26rpx;
			}
		}
	}
	
	.info-fillin {
		background: #fff;
		padding: 0 24rpx;
		border-radius: 12rpx;
		margin-top: 20rpx;
		.selct-placeholder {
			color: #999;
			font-size: 28rpx;
		}
		.fillin-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 30rpx 0;
			border-bottom: 2rpx solid #e9e9e9;
			&:last-of-type {
				border-bottom: 0;
			}
			.fillin-item-content {
				font-size: 28rpx;
				font-weight: 500;
				color: #1a1a1a;
				display: flex;
				align-items: center;
				text {
					margin-right: 10rpx;
				}
				.u-radio {
					margin-right: 40rpx;
					&:last-of-type {
						margin-right: 0;
					}
				}
			}
		}
		.fillin-item-title {
			color: #666;
			font-size: 28rpx;
			line-height: 40rpx;
		}
	}

	.opeart {
		padding: 16rpx 28rpx;
		display: flex;
		position: absolute;
		left: 0;
		bottom: 0;
		width: 100vw;
		background: #fff;

		.opeart-btn {
			flex: 1;
			height: 88rpx;
			border-radius: 16rpx;
			font-size: 32rpx;
			text-align: center;
			line-height: 88rpx;
			background: #1777ff;
			color: #fff;
		}
	}
</style>